package tech.kunyuan.utils;

import org.springframework.stereotype.Service;

/**
 * Description:
 *
 * @Author: ky
 * DateTime: 2022-10-21 10:54
 */
@Service
public class ThreadUtils implements Runnable{
    private int total = 100;
    Object obj = new Object();

    @Override
    public void run(){
        while(true){
            synchronized (obj){
                //System.out.println("原始当前数量:" + total);
                if(total > 0){
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    total --;
                    System.out.println(Thread.currentThread().getName() + ":\t当前剩余数量:" + total);
                }else{
                    System.out.println("已经没票了>>>");
                    break;
                }
            }
        }
    }
}
